package com.hopsof.tools.uimanagerdefaultslookup;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;


/**
 *        Licensed to the Apache Software Foundation (ASF) under one
 *      or more contributor license agreements.  See the NOTICE file
 *      distributed with this work for additional information
 *      regarding copyright ownership.  The ASF licenses this file
 *      to you under the Apache License, Version 2.0 (the
 *      "License"); you may not use this file except in compliance
 *      with the License.  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *      Unless required by applicable law or agreed to in writing,
 *      software distributed under the License is distributed on an
 *      "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *      KIND, either express or implied.  See the License for the
 *      specific language governing permissions and limitations
 *      under the License.
 *      
 *      Copyright 2012 Hopsof
 *      
 * @author Brandon Murphy
 * @see <a href="http://www.hopsof.com/">http://www.hopsof.com/</a> 
 *
 */


public class AboutBox extends JDialog
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	public class ImageView extends JPanel
	{

	    /**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		private ImageIcon image;

	    public ImageView(String imageName) throws IOException 
	    {          
	    	URL url = AboutBox.class.getClassLoader().getResource(imageName);
	    	
	    	if(url == null)
	    	{
	    		image = new ImageIcon(ImageIO.read(new File("bin/" + imageName)));
	    	}
	    	else
	    	{
	    		image = new ImageIcon(url);
	    	}
	    	
	        this.setPreferredSize(new Dimension(image.getIconWidth(), image.getIconHeight()));
	    }

	    public void paintComponent(Graphics g) 
	    {
	        g.drawImage(image.getImage(), 0, 0, null);
	    }

	}


	public AboutBox(Frame parent) 
	{
		super(parent);
		
		this.setTitle("About UIManagerDefaultsLookup");
		this.setLayout(new BorderLayout());
		                            
		JButton closeButton			= new JButton("Close");
		
		
		JLabel text = new JLabel("<html><h1>About</h1><h3>Created by</h3>Hopsof<br><br><h3>Author</h3>Brandon Murphy<br><br><h3>Please Visit</h3><a href=\"http://www.hopsof.com/\">http://www.hopsof.com/</a><br><br><h3>Copyright</h3>2012 Hopsof<br><br><h3>License</h3>Licensed to the Apache Software Foundation (ASF) under one<br>or more contributor license agreements.  See the NOTICE file<br>distributed with this work for additional information<br>regarding copyright ownership.");
		ImageView image = null;
		try {
			image = new ImageView("com/hopsof/tools/uimanagerdefaultslookup/AboutImage.png");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		text.setBackground(Color.WHITE);
		text.setOpaque(true);
		
		this.add(new JScrollPane(text), BorderLayout.CENTER);	
		this.add(image, BorderLayout.WEST);
		this.add(closeButton, BorderLayout.PAGE_END);
		
		final Dialog dialog = this;
		
		closeButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				dialog.setVisible(false);
			}});

		this.setLocationByPlatform(true);
		this.setModal(true);
		
		this.pack();
		this.setSize((int)(this.getHeight()*1.3), this.getHeight());
		this.setResizable(false);
		this.setBackground(Color.WHITE);
	}
}
